package com.example.bloomFilter;

import com.google.common.hash.BloomFilter;
import com.google.common.hash.Funnels;

import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;

public class BloomFilterExample {
    public static void main(String[] args) {
        // 创建一个布隆过滤器，指定预期插入的元素数量和期望的误判率
        int expectedInsertions = 1000000;
        double falsePositiveProbability = 0.01; // 1% 的误判率
        BloomFilter<String> bloomFilter = BloomFilter.create(Funnels.stringFunnel(Charset.defaultCharset()), expectedInsertions, falsePositiveProbability);
        List<String> str = new ArrayList<>();
        long k = 0;
        for(long i = 0 ;i < 100000000002l;i++){
            k = i;
            bloomFilter.put("example_"+i);
            //str.add("example_"+i);
            System.out.println(k);
        }
        System.out.println("结束");
       /* // 向布隆过滤器中添加元素
        bloomFilter.put("example1");
        bloomFilter.put("example2");
        bloomFilter.put("example3");

        // 检查元素是否在布隆过滤器中
        System.out.println(bloomFilter.mightContain("example1")); // true
        System.out.println(bloomFilter.mightContain("example4")); // false*/
    }
}
